Computer programs commonly use a combination of static and dynamic memory allocation. A static memory allocation occurs when a program loads, before it executes. If the static allocations by a particular program exceed the available memory, the operating system will not load the program. A dynamic memory allocation occurs after a program loads, while it is executing. When a dynamic allocation failure indicates that required resources are not available, the program may not be able to continue normal execution.
In such a case, the preferred behavior is to indicate to the user that a problem has occurred, gracefully terminate any outstanding actions, and then exit the program. Graceful termination might include closing any open files, restoring the display to an initial state, and terminating any network connections and/or connections with external devices. Graceful termination could also include notifying another program—either local or remote—that this program is exiting.
However, graceful termination after a dynamic allocation failure can be difficult to implement when the program uses an event-driven architecture with an operating system that provides multi-tasking. In this type of architecture, at least some communication between program components (for example, but not limited to, tasks, processes or threads) occurs via events or messages rather than function calls. Therefore, when a component attempts to dynamically allocate memory for an event and this event allocation fails, the component is unable to notify other components of the failure, thus preventing graceful termination.